<?php
require 'TVB/pms/pdes/common/bootstrap.php';


if(empty($_REQUEST['q']))
{
	exit('[]');
}

$country_sql    = 'select id,system_label as name from country where system_label like :q';
$province_sql   = 'select id,system_label as name from province_state_prefecture where country_id = :cid and system_label like :q';

if(isset($_REQUEST['country_id']))
{
	if(empty($_REQUEST['country_id'])){
		exit('[]');
	}
	$sql = $province_sql;
	$param = array(':cid'=>(int)$_REQUEST['country_id']);
}
else
{
	$sql = $country_sql;
	$param = array();
}
$param[':q'] = '%'.$_REQUEST['q'].'%';

$rs = Model::selectBySql($sql,$param);

exit(json_encode($rs));
